<?php

class AdpushAction extends CommonAction {

    // 查询数据
    public function index() {
        //$Adpush = M("Adpush");
        //$list = $Adpush->limit(3)->order('id desc')->select();
        //$this->list =  $list;
        $this->display();
    }
	public function add() {

	
        $this->display();
    }
	public function addjson() {
		$adplace = D('Adplace')->select();
		echo json_encode($adplace);
		
    }
	public function dindanjson() {
		$OrderInfo = D('OrderInfo')->select();
		//print_r($OrderInfo);

		echo json_encode($OrderInfo);
		
    }



	 public function indexjson() {
        $Adpush = M("Adpush");
        $list = $Adpush->limit(3)->order('id desc')->select();
		//echo $Adpush->getLastSql();
		//dump($list);exit;
		$i = 0;
		foreach($list AS $row ){
			$adpush[$i]['table_id'] = $row['id'];
			$adpush[$i]['table_name'] = $row['name'];
			$adpush[$i]['table_channel']['channelid'] = $row['channelid'];
			$adpush[$i]['table_channel']['channelname'] = $row['channelname'];
			$adpush[$i]['table_adplace']['adplaceid'] = $row['adplaceid'];
			$adpush[$i]['table_adplace']['adplacename'] = $row['adplacename'];
			
			
			$adpush[$i]['table_type']['typeid'] = $row['typeid'];
			$adpush[$i]['table_type']['typename'] = $row['typename'];
			$adpush[$i]['table_width'] = $row['width'];
			$adpush[$i]['table_height'] = $row['height'];
			
			$adpush[$i]['table_status'] = $row['status'];
			$i++;
			}
		$adpushHtml['total'] = $row_sum['num'];
		$adpushHtml['rows'] = $adpush;
		echo json_encode($adpushHtml);
		
    }

    // 写入数据
    public function insert() {
        //$Adpush = D("Adpush");
       /* 
		if ($vo = $Adpush->create()) {
		print_r($vo);
            $list = $Adpush->add();
            if ($list !== false) {
                //$this->success('数据保存成功！',U('Index/index'));
            } else {
                //$this->error('数据写入错误！');
            }
        } else {
		//print_r($Adpush);echo "--------";
            //$this->error($Adpush->getError());
        }
		*/
		$Materials = D("Materials");
		$Materials->customerid  = '1';
		$Materials->content  = '流年';
		$Materials->status  = '1';
        $materialsid = $Materials->add();    
		print_r($materialsid);echo "--------";
		
		
		$Adpush = D("Adpush");
		$Adpush->channelid     = '1';
        $Adpush->adplaceid  = 1;
		$Adpush->orderid     = '1';
        $Adpush->stime  = "2013-12-01 23:00:31";
		$Adpush->etime     = '2013-12-01 23:00:31';
        ///$Adpush->stime  = 1;
		$Adpush->materialid     = $materialsid;
        $Adpush->condition  = 1;
		$Adpush->status  = 1;
		 $Adpushid = $Adpush->relation(true)->add();
		   dump($Adpush->data(),true) ;
		   
		   
		$Addate = D("Addate");
		$Addate->adplaceid  = '1';
		$Addate->channelid  = '1';
		$Addate->orderid  = '1';
		$Addate->date  = '2013-11-25';
		$Addate->status  = '1';
        $Addateid = $Addate->add();    
		print_r($Addateid);echo "--------";   
		   
        // 用户档案数据
		/*
        $Adpush->date  = array(
			array(
				'adplaceid'     => '1',
				'channelid'  => '1',
				'date'     => '2013-11-25',
				'orderid'  => '1',
				'status'  => '1',
			),array(
				'adplaceid'     => '1',
				'channelid'  => '1',
				'date'     => '2013-11-25',
				'orderid'  => '1',
				'status'  => '1',
			),
		 );
		 */
		
        // 关联添加用户数据
         
    }

    // 更新数据
    public function update() {
        $Adpush = D("Adpush");
        if ($vo = $Adpush->create()) {
            $list = $Adpush->save();
            if ($list !== false) {
                $this->success('数据更新成功！',U('Index/index'));
            } else {
                $this->error("没有更新任何数据!");
            }
        } else {
            $this->error($Adpush->getError());
        }
    }

    // 删除数据
    public function delete($id) {
        if (!empty($id)) {
            $Adpush = M("Adpush");
            $result = $Adpush->delete($id);
            if (false !== $result) {
                $this->success('删除成功！');
            } else {
                $this->error('删除出错！');
            }
        } else {
            $this->error('ID错误！');
        }
    }

    // 编辑数据
    public function edit($id) {
        if (!empty($id)) {
            $Adpush = M("Adpush");
            $vo = $Adpush->getById($id);
            if ($vo) {
                $this->vo   =   $vo;
                $this->display();
            } else {
                $this->error('数据不存在！');
            }
        } else {
            $this->error('数据不存在！');
        }
    }
}
?>